<?php

namespace app\common\command\addon;

use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;

class AddonCreate extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('addon:create')
            ->addOption('addon', 'a', Option::VALUE_REQUIRED, '插件名')
            ->addOption('type', 't', Option::VALUE_OPTIONAL, '插件类型')
            ->addOption('title', null, Option::VALUE_OPTIONAL, '插件名称')
            ->addOption('intro', null, Option::VALUE_OPTIONAL, '插件介绍')
            ->addOption('author', null, Option::VALUE_OPTIONAL, '插件作者')
            ->addOption('website', null, Option::VALUE_OPTIONAL, '插件作者官网')
            ->addOption('autorouter', null, Option::VALUE_OPTIONAL, '是否开启自动路由')
//            ->addOption('version', null, Option::VALUE_NONE, '插件版本')
            ->addOption('state', null, Option::VALUE_OPTIONAL, '插件状态')
            ->addOption('require', null, Option::VALUE_OPTIONAL, '依赖的插件')
            ->setDescription('Create addon');
    }

    protected function execute(Input $input,Output $output)
    {

        $addon = $input->getOption('addon', '');
        if(empty($addon)){
            $output->error('插件名称不能为空');
            return;
        }
        $type = $input->getOption('type', 'addons');
        if(empty($type)){
            $type = 'addons';
        }
        $title = $input->getOption('title', '');
        if(empty($title)){
            $title = $addon;
        }
        $intro = $input->getOption('intro', '');
        if(empty($intro)){
            $intro = '插件介绍';
        }
        $author = $input->getOption('author', '');
        if(empty($author)){
            $author = 'your name';
        }
        $website = $input->getOption('website', '');
        if(empty($website)){
            $website = '';
        }
        $autorouter = $input->getOption('autorouter', 1);
        if(empty($autorouter)){
            $autorouter = 1;
        }
        $state = $input->getOption('state', 0);
        if(empty($state)){
            $state = 0;
        }
        $require = $input->getOption('require', '');
        if(empty($require)){
            $require = '';
        }
        $version = $input->getOption('version', '1.0.0');
        if(empty($version)){
            $version = '1.0.0';
        }
        \app\common\library\addon\Addon::createAddons($addon, $type, $title, $intro, $author, $website, $autorouter, $version, $state, $require);
        // 指令输出
        $this->output->writeln('create addon!');
    }
}